const sequelize = require("../sequelize_ins");
const { DataTypes } = require("sequelize");
const { get_permutation_combinations } = require("../../utils");

const core = sequelize.define("pb", {
  type: DataTypes.STRING,
});

module.exports = {
  core,

  get_pb_initial_data(nums) {
    return get_permutation_combinations(nums).map((type) => ({ type }));
  },

  async is_pb_data_initial() {
    return (await this.core.findOne()) !== null;
  },

  async get_pb_of_id(id) {
    const query = { where: { id } };
    return Array.isArray(id)
      ? await this.core.findAll(query)
      : await this.core.findOne(query);
  },
};
